package xmlRW;

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;



public class ReadXml {

	
	public static Document document;
	public static String FilePath = "config/Path.xml";
	
	public ReadXml() throws DocumentException {
		File file = new File(FilePath);
		SAXReader reader = new SAXReader();
		document = reader.read(file);
	}
	
	public ReadXml(String FileName) throws DocumentException {
		File file = new File(FileName);
		SAXReader reader = new SAXReader();
		document = reader.read(file);
	}
	
	

	
	public static String getAttributes(String XPath){
		return selectNode(XPath); 
	}
	


	private static String selectNode(String xpath) {
		Node node = document.selectSingleNode(xpath);
		return node == null ? "" : node.getText();
	}

	@SuppressWarnings({ "unused", "rawtypes" })
	private List<String> selectNodes(String xpath) {
		List<String> results = new ArrayList<String>();
		List elements = document.selectNodes(xpath);
		Iterator iter = elements.iterator();
		while (iter.hasNext()) {
			results.add(((Element) iter.next()).getText());
		}
		return results;
	}
	
}
